<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\grid\GridView;
use backend\helpers\ActionButton;
use backend\helpers\FileViewHelper;
use backend\helpers\DateTimeHelper;
use backend\models\Project;
use kartik\export\ExportMenu;

/* @var $this yii\web\View */
/* @var $model backend\models\Project */

$this->registerJs(
    "$('.js-file-exist').tooltip();",
);

$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Проекты', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

$this->params['id'] = $model->id;

\yii\web\YiiAsset::register($this);

?>
<div class="container project-view">

    <h1 class="main-title"><?= Html::encode($this->title) ?></h1>

    <div class="row">
        <div class="col-sm-11"><?= $this->render('/project/_menu') ?></div>
        <div class="col-sm-1"><?= ActionButton::delete($model->id, 'Вы точно хотите удалить информацию о проекте?', 'deleteProject') ?></div>
    </div>


    <div class="project-summary">
        <h3 class="project-summary__title">Бюджет</h3>
        <? if (!$model->is_proxy): ?>
        <p>остаток: <?= Yii::$app->formatter->asCurrency($model->getDonations()->sum('price') - $model->getContracts()->sum('total_price')) ?></p>
        <p>количество договоров: <?= $contractDataProvider->getTotalCount() ?></p>
        <p>сумма заключенных договоров: <?= Yii::$app->formatter->asCurrency($model->getContracts()->sum('total_price')) ?></p>
        <? else: ?>
        <p>Проект-прокси не подразумевает ведения бюджета.</p>
        <? endif; ?>
        <hr>
        <h3 class="project-summary__title">Время</h3>
        <?
            if($model->status == Project::STATUS_ACTIVE)
            {
                if(DateTimeHelper::getNowDate() < $model->date_realize)
                {
                    echo '<p><span class="badge badge-success">осталось: ' . DateTimeHelper::diffPeriod(DateTimeHelper::getNowDate(), $model->date_realize) . '</span></p>';
                }
                else
                {
                    echo '<p><span class="badge badge-danger">просрочка: ' . DateTimeHelper::diffPeriod(DateTimeHelper::getNowDate(), $model->date_realize) . '</span></p>';
                }
            }
            if($model->status == Project::STATUS_CLOSE)
            {
                echo '<p><span class="badge">проект закрыт</span></p>';
            }
        ?>
    </div>

    <h2 class="table-header">Проект</h2>

    <?= DetailView::widget([
        'model' => $model,
        'options' => ['class' => 'table table-striped detail-view table-headered'],
        'attributes' => [
            'id',
            'title', 
            'description:paragraphs',
            [
                'label' => 'Ответственный бухгалтер',
                'attribute' => 'accountant.profile.name',
            ],
            [
                'label' => 'Куратор',
                'attribute' => 'curator.profile.name',
            ],
            [
                'label' => 'Рабочая смета',
                'value' => function($model) {
                    return HTML::a($model->url_work_budget, $model->url_work_budget, ['target' => '_blank']);
                },
                'format' => 'raw',
            ],
            [
                'attribute'=>'is_proxy',
                'value' => function ($model) {
                    return backend\helpers\SimpleFlagHelper::statusName($model->is_proxy);
                },
                'format' => 'raw'
            ],
        ],
    ]) ?>

</div>

